//
// Created by whz on 2022/5/23.
//
#include <thread>
#include <condition_variable>
#include <memory>
#include <iostream>
#include "../src/buffer/buffer_pool.h"

using namespace std::chrono;
class Test{
private:
    class FlushService {
    private:
        volatile  bool is_run = false;
        std::shared_ptr<std::thread> flush_thread;
        std::unordered_set<PAGE *> flush_set;
    public:
        FlushService(std::unordered_set<PAGE *> &flush_set) {
            this->flush_set = flush_set;
        }

        void start() {
            is_run = true;
            std::cout << "FlushService start" << std::endl;
            flush_thread = std::make_shared<std::thread>(&FlushService::run, this);
        }

        void stop() {
            std::cout << "FlushService stop" << std::endl;
            is_run = false;
            flush_thread->join();
        }

        void run() const {
            while (is_run) {
//                std::this_thread::sleep_for(std::chrono::seconds(1));
//                for (auto page: flush_set) {
//                    auto item = flush_set.find(page);
//                    flush(page);
//                }
            }
            std::cout << "FlushService flush all" << std::endl;
        }

    };
    std::shared_ptr<FlushService> flush_service;
    std::unordered_set<PAGE *> set;
public:
    Test(){
        flush_service=std::make_shared<FlushService>(set);
        flush_service->start();
    }
    ~Test(){
     flush_service->stop();
    }
};


//int main() {
//    Test t;
//
//}